package com.cy.module.controller;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.misc.CharacterEncoder;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.Map;

@Controller
public class TemplateController {

//    @RequestMapping("/doHealth")
//    public String doHealth(){
//        return "default";
//    }
    @RequestMapping("/health.html")
    @ResponseBody
    public Map<String, Object> doHealth(){
        Map<String,Object> map=new HashMap<>();
        map.put("username","tony");
        map.put("state",true);
        return map;
    }
    @RequestMapping("/doPrint")
    @ResponseBody
    public void  doPrint(HttpServletResponse response) throws Exception{
        Map<String,Object> map=new HashMap<>();
        map.put("username","托尼");
        map.put("state",true);
        ObjectMapper om=new ObjectMapper();
        String jsonStr=om.writeValueAsString(map);
        System.out.println("jsonStr="+jsonStr);
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().println(jsonStr);
    }
}
